// 此处对ajax 进行了二次封装  => 调用ajax请求,返回进行中状态的Promise实例
function request(url, params = {}, type = "get") {
    return new Promise(function (resolve, reject) {
        $.ajax({
            type: type,
            url: url,
            data: { ...params },
            dataType: "json",
            success: function (data) { //形式参数(接口返回的响应数据 )
                resolve(data);
            }
        })
    })
}


// 箭头函数简写

// 登录
const login = params => request("../php/login.php", params, "post");

// 判断用户名是否重复
const isExistUser = params => request("../php/isExistUser.php", params);

// 注册
const register = params => request("../php/register.php", params, "post");

// 根据名称查询商品及排序分页
const indexSearchGradeOrderLimit = params => request("php/searchGradeOrderLimit.php", params)

const searchGradeOrderLimit = params => request("../php/searchGradeOrderLimit.php", params)

// 商品详情
const searchGoodsByGoodsId = params => request("../php/searchGoodsByGoodsId.php", params);

// 加入购物车
const addToShopingCar = params => request("../php/addToShopingCar.php", params, "post");

// 购物车页面
const searchShoppingCarByUser = params => request("../php/searchShoppingCarByUser.php", params, "post");

// type = 0 => 减法   {type:0,id}
// type = 1 => 加法   {type:1,id}
// type = 2 => 失去焦点  直接改变内容  => buyNum   {type:2,id,buyNum}
const updateShoppingCarById = params => request("../php/updateShoppingCarById.php", params, "post");

const reduceGoods = params => request("../php/updateShoppingCarById.php", { type: 0, ...params }, "post");
const addGoods = params => request("../php/updateShoppingCarById.php", { type: 1, ...params }, "post");
const changeGoods = params => request("../php/updateShoppingCarById.php", { type: 2, ...params }, "post");

const delGoods = params => request("../php/deleteShoppingCarById.php", params, "post");

const updateGoodsChecked = params => request("../php/updateShoppingCarCheckedById.php", params, "post");

